package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.shop.Brand;
import com.mvp.shq.washer.entity.shop.Category;
import com.mvp.shq.washer.utils.ImageUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by shq1 on 2017/9/30.
 */

public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> {

    public Context context;
    private List<Brand> brands;
    private ImageUtil imageUtil;
    private OnCategoryItemClickLinstener linstener;
    public CategoryAdapter(Context mContext,List<Brand> list,OnCategoryItemClickLinstener clickLinstener){
        mContext = mContext;
        brands = list;
        imageUtil = new ImageUtil(mContext);
        linstener = clickLinstener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_category, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.categoryName.setText(brands.get(position).getBrandName());
        imageUtil.loadUrlImage(brands.get(position).getBrandImg(),holder.img);
        holder.llContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                linstener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return brands.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img)
        ImageView img;
        @BindView(R.id.category_name)
        TextView categoryName;
        @BindView(R.id.ll_container)
        LinearLayout llContainer;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
    public interface OnCategoryItemClickLinstener{
        void onClick(int position);
    }
}
